package gui;

import javax.swing.JPanel;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

public class GridBagPanel extends JPanel {
    /**
     * description: GridBagPanel
     * 网格包布局管理封装
     * @author what-is-me
     * @date 2022/1/3 23:27
     */
    GridBagLayout gridBag;

    private GridBagPanel(GridBagLayout gridBag) {
        /**
         * Description: GridBagPanel
         * @param gridBag:java.awt.GridBagLayout
         * @return {@link null}
         * @throws 
         * @author what-is-me
         * @date 2022/1/3 23:27
         */
        super(gridBag);
        this.gridBag = gridBag;
    }

    public GridBagPanel() {
        /**
         * Description: GridBagPanel
         * @param :
         * @return {@link null}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:28
         */
        this(new GridBagLayout());
    }

    public GridBagPanel add(Component comp, int gridx, int gridy, int gridwidth, int gridheight, double zoomMultiples, int w) {
        /**
         * Description: add
         * @param comp:java.awt.Component 加入的组件
         * @param gridx:int 第几列（从0开始）
         * @param gridy:int 第几行（从0开始）
         * @param gridwidth:int 宽度
         * @param gridheight:int 高度
         * @param zoomMultiples:double 放大比例（0为不放大）
         * @param w:int 组件与边框的距离（单位为px)
         * @return {@link GridBagPanel}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:28
         */
        gridBag.addLayoutComponent(comp, new GridBagConstraints(gridx, gridy, gridwidth, gridheight, zoomMultiples,
                zoomMultiples, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(w, w, w, w), 0, 0));
        add(comp);
        return this;
    }

    public GridBagPanel add(Component comp, int gridx, int gridy, int gridwidth, int gridheight) {
        /**
         * Description: add
         * @param comp:java.awt.Component 加入的组件
         * @param gridx:int 第几列（从0开始）
         * @param gridy:int 第几行（从0开始）
         * @param gridwidth:int 宽度
         * @param gridheight:int 高度
         * @return {@link gui.GridBagPanel}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:31
         */
        return add(comp, gridx, gridy, gridwidth, gridheight, 0, 0);
    }
}